Repository navigation
Conversation
When GIT_BRANCH_NAME names the branch that is already checked out, `git checkout -b` fails and the script reported "Branch already exists" and exited 1, unless --allow-existing-branch was passed. The branch is already in the requested state, so handle it the way the --allow-existing-branch path does and succeed without switching. Applied to the bash, PowerShell and Python scripts. A GIT_BRANCH_NAME naming a different existing branch still fails. Fixes github#5003 Assisted-by: Claude Code (model: Claude Sonnet 5.5, autonomous)
Add a PowerShell twin of the bash test for GIT_BRANCH_NAME naming the checked-out branch, use a case-sensitive comparison in the new PowerShell clause so a differently-cased branch is not mistaken for the current one, and document the behaviour in speckit.git.feature.md. Assisted-by: Claude Code (model: Claude Sonnet 5.5, autonomous)
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Required PowerShell rejection coverage and Windows PowerShell 5.1 compatibility evidence remain missing.
2 open issues
What changed in this PR
Fixes #5003 by letting the git extension accept GIT_BRANCH_NAME when it names the current branch.
Changes:
- Align Bash, PowerShell, and Python no-op behavior.
- Add success regressions and Bash/Python rejection coverage.
- Document the override behavior.
AI-generated review for the requester by GitHub Copilot (model: unknown; autonomous). Tests were not run.
| File | Description |
|---|---|
| tests/extensions/git/test_git_extension.py | Adds Bash and PowerShell no-op tests. |
| tests/extensions/git/test_git_extension_python_parity.py | Tests no-op and rejection parity. |
| extensions/git/scripts/python/create_new_feature_branch.py | Accepts the current-branch override. |
| extensions/git/scripts/powershell/create-new-feature-branch.ps1 | Accepts the current-branch override. |
| extensions/git/scripts/bash/create-new-feature-branch.sh | Accepts the current-branch override. |
| extensions/git/commands/speckit.git.feature.md | Documents current-branch success. |
Review effort: Max
| if ($AllowExistingBranch) { | ||
| # An explicit GIT_BRANCH_NAME naming the checked-out branch is | ||
| # already satisfied, so treat it like -AllowExistingBranch. | ||
| if ($AllowExistingBranch -or ($env:GIT_BRANCH_NAME -and $currentBranch -ceq $branchName)) { |
| assert data["BRANCH_NAME"] == "jdoe/2026-app/042-custom-branch" | ||
| assert data["FEATURE_NUM"] == "042" | ||
|
|
||
| def test_git_branch_name_override_naming_current_branch_is_noop(self, tmp_path: Path): |
Collaborator
|
Please address Copilot feedback |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #5003.
Description
With
GIT_BRANCH_NAMEset to the branch that is already checked out,git checkout -bfails, so the feature-branch script reported "Branch already exists" and exited 1 unless--allow-existing-branchwas passed. The branch is already in the requested state, so the bash, PowerShell and Python scripts now succeed without switching, as the--allow-existing-branchpath does. AGIT_BRANCH_NAMEnaming a different existing branch still fails.Testing
Existing and new tests in the git extension suites: 129 passed, 0 failed (the new tests fail without the fix). I did not run the other checks.
uv run specify --helpuv sync && uv run pytestAI Disclosure
AI disclosure: Code and tests written by Claude Code (model: Claude Sonnet 5.5, autonomous), reviewed by two further agent passes.
Assisted-by: Claude Code (model: Claude Sonnet 5.5, autonomous)